<!--
 * @Author: huangpx
 * @Date: 2023-04-22 14:58:05
 * @LastEditors: huangpx
 * @LastEditTime: 2023-06-26 11:34:24
 * @Description: file content
-->
<template>
    <div>
        <!-- <h1>基础用法</h1>
        <div style="height:200px">
            <tree-virtual :data="data"/>
        </div> -->
        <h1>懒加载法</h1>
           <div style="height:200px">
                <tree-virtual  
                :props="props"
                :load="loadNode"
                lazy
                highlight-current
                show-checkbox
                />
           </div>
    </div>
</template>
<script>
  export default {
    data() {
      return {
        data: [{
          label: '一级 1',
          children: [{
            label: '二级 1-1',
            children: [{
              label: '三级 1-1-1'
            }]
          }]
        }, {
          label: '一级 2',
          children: [{
            label: '二级 2-1',
            children: [{
              label: '三级 2-1-1'
            }]
          }, {
            label: '二级 2-2',
            children: [{
              label: '三级 2-2-1'
            }]
          }]
        }, {
          label: '一级 3',
          children: [{
            label: '二级 3-1',
            children: [{
              label: '三级 3-1-1'
            }]
          }, {
            label: '二级 3-2',
            children: [{
              label: '三级 3-2-1'
            }]
          }]
        }],
        
        props: {
          label: 'name',
          children: 'zones',
          isLeaf: 'leaf'
        },
      };
    },
    methods:{
         loadNode(node, resolve) {
        if (node.level === 0) {
          return resolve([{ name: 'region' }]);
        }
        if (node.level > 1) return resolve([]);
        setTimeout(() => {
          const data = [{
            name: 'leaf',
            leaf: true
          }, {
            name: 'zone'
          }];

          resolve(data);
        }, 500);
      }
    }
  };
</script>